package cn.usian.controller;

import cn.usian.pojo.Emp;
import cn.usian.service.EmpService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class EmpController {
    @Resource
    private EmpService empService;

    @RequestMapping("findAll")
    public String findAll(Model model){
        List<Emp> list=empService.findAll();
        model.addAttribute("list",list);
        return "emp";
    }

    @RequestMapping("toadd")
    public String toadd(){
        return "add";
    }

    @RequestMapping("add")
    public String add(Emp emp){
        empService.add(emp);
        return "redirect:/findAll";
    }

    @RequestMapping("update")
    public String update(Emp emp){
        empService.update(emp);
        return "redirect:/findAll";
    }

    @RequestMapping("delete")
    public String delete(Integer eid){
        empService.delete(eid);
        return "redirect:/findAll";
    }

    @RequestMapping("findByEid")
    public String findByEid(Integer eid,Model model){
        Emp emp=empService.findByEid(eid);
        model.addAttribute("emp",emp);
        return "update";
    }
}
